<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>云边集群快速搭建的解决方案 | 美的楼宇科技研究院</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="iBUILDING作为智慧建筑的数字践行者，致力于用数字的眼光建筑世界。以科技赋能楼宇，构建数字建筑生态，共创更美好的智慧空间。Make iBUILDING come TRUE。">
    <meta name="keywords" content="iBUILDING,ibuilding">
    <meta name="theme-color" content="#11a8cd">
    <meta name="baidu-site-verification" content="code-j1XZ46JIBR">
    
    <link rel="preload" href="/assets/css/0.styles.af9b49f9.css" as="style"><link rel="preload" href="/assets/js/app.ffe9b366.js" as="script"><link rel="preload" href="/assets/js/2.9760a328.js" as="script"><link rel="preload" href="/assets/js/13.3fd35f26.js" as="script"><link rel="prefetch" href="/assets/js/10.1ca8e9a5.js"><link rel="prefetch" href="/assets/js/11.f84ca260.js"><link rel="prefetch" href="/assets/js/12.5d62fb57.js"><link rel="prefetch" href="/assets/js/14.d428d44b.js"><link rel="prefetch" href="/assets/js/15.752b1e82.js"><link rel="prefetch" href="/assets/js/16.f33da816.js"><link rel="prefetch" href="/assets/js/17.4a25f92e.js"><link rel="prefetch" href="/assets/js/18.3ad538ff.js"><link rel="prefetch" href="/assets/js/19.4957cef9.js"><link rel="prefetch" href="/assets/js/20.264d8716.js"><link rel="prefetch" href="/assets/js/21.2e6c7b77.js"><link rel="prefetch" href="/assets/js/22.4abc22b5.js"><link rel="prefetch" href="/assets/js/23.52e85444.js"><link rel="prefetch" href="/assets/js/24.ae24e643.js"><link rel="prefetch" href="/assets/js/25.5596a9ad.js"><link rel="prefetch" href="/assets/js/26.d952969d.js"><link rel="prefetch" href="/assets/js/27.7711bd91.js"><link rel="prefetch" href="/assets/js/3.0b2e2ac4.js"><link rel="prefetch" href="/assets/js/4.d41f70ee.js"><link rel="prefetch" href="/assets/js/5.603be3f5.js"><link rel="prefetch" href="/assets/js/6.36f53e66.js"><link rel="prefetch" href="/assets/js/7.8566b5df.js"><link rel="prefetch" href="/assets/js/8.82830ba8.js"><link rel="prefetch" href="/assets/js/9.d949e13c.js">
    <link rel="stylesheet" href="/assets/css/0.styles.af9b49f9.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://static-btri.midea.com/mfs/1001/1656483801940.svg" alt="美的楼宇科技研究院" class="logo"> <span class="site-name can-hide">美的楼宇科技研究院</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📖开源项目" class="dropdown-title"><!----> <span class="title" style="display:;">📖开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/driver-box/" class="nav-link">driver-box</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发者社区" class="dropdown-title"><!----> <span class="title" style="display:;">开发者社区</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/about.html" class="nav-link">技术博客</a></li><li class="dropdown-item"><!----> <a href="https://openibuilding.midea.com/home" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开放平台
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源仓库" class="dropdown-title"><!----> <span class="title" style="display:;">开源仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/iBUILDING-X" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📖开源项目" class="dropdown-title"><!----> <span class="title" style="display:;">📖开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/driver-box/" class="nav-link">driver-box</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发者社区" class="dropdown-title"><!----> <span class="title" style="display:;">开发者社区</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/about.html" class="nav-link">技术博客</a></li><li class="dropdown-item"><!----> <a href="https://openibuilding.midea.com/home" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开放平台
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源仓库" class="dropdown-title"><!----> <span class="title" style="display:;">开源仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/iBUILDING-X" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/blog/about.html" class="sidebar-link">技术团队</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>边缘网关</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/edge-env/" class="sidebar-link">边缘环境搭建</a></li><li><a href="/pages/faeaa1/" class="sidebar-link">基于NanoPi的边缘网关镜像制作</a></li><li><a href="/pages/416f35/" class="sidebar-link">基于HTTP插件的模拟设备数据上报</a></li><li><a href="/pages/9caacc/" aria-current="page" class="active sidebar-link">云边集群快速搭建的解决方案</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/9caacc/#一、背景" class="sidebar-link">一、背景</a></li><li class="sidebar-sub-header level2"><a href="/pages/9caacc/#二、云端部署" class="sidebar-link">二、云端部署</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/9caacc/#_2-1-基础环境初始化" class="sidebar-link">2.1 基础环境初始化</a></li><li class="sidebar-sub-header level3"><a href="/pages/9caacc/#_2-2-启动kubeedge云端服务" class="sidebar-link">2.2 启动KubeEdge云端服务</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/9caacc/#三、边端部署" class="sidebar-link">三、边端部署</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/9caacc/#_3-1-基础环境初始化" class="sidebar-link">3.1 基础环境初始化</a></li><li class="sidebar-sub-header level3"><a href="/pages/9caacc/#_3-2-搭建kubeedge环境" class="sidebar-link">3.2 搭建KubeEdge环境</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/9caacc/#四、效果演示" class="sidebar-link">四、效果演示</a></li><li class="sidebar-sub-header level2"><a href="/pages/9caacc/#五、开启反向隧道" class="sidebar-link">五、开启反向隧道</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/9caacc/#_5-1-云端" class="sidebar-link">5.1 云端</a></li><li class="sidebar-sub-header level3"><a href="/pages/9caacc/#_5-2-边缘端" class="sidebar-link">5.2 边缘端</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/9caacc/#问题集锦" class="sidebar-link">问题集锦</a></li></ul></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>blog</span></li><li data-v-06225672><span data-v-06225672>边缘网关</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="javascript:;" data-v-06225672>郑俊伟</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-06-16</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">云边集群快速搭建的解决方案<!----></h1> <div class="page-slot page-slot-top">
    <div class="wwads-cn wwads-horizontal page-wwads" data-id="136"></div>
    <style>
      .page-wwads{
        width:100%!important;
        min-height: 0;
        margin: 0;
      }
      .page-wwads .wwads-img img{
        width:80px!important;
      }
      .page-wwads .wwads-poweredby{
        width: 40px;
        position: absolute;
        right: 25px;
        bottom: 3px;
      }
      .wwads-content .wwads-text, .page-wwads .wwads-text{
        height: 100%;
        padding-top: 5px;
        display: block;
      }
  </style>
  </div> <div class="theme-vdoing-content content__default"><h1 id="探索云边一体化-环境搭建"><a href="#探索云边一体化-环境搭建" class="header-anchor">#</a> 探索云边一体化：环境搭建</h1> <h2 id="一、背景"><a href="#一、背景" class="header-anchor">#</a> 一、背景</h2> <p>iBUILDING平台在云边一体化方向的探索中，一直坚持通过不断创新和完善自身的技术和服务，为用户提供更加便捷、高效、安全的边缘计算解决方案。</p> <p>本期带来的是关于《云边集群快速搭建的解决方案》的分享。</p> <p><strong>适配环境</strong></p> <ul><li>架构：amd64、arm64</li> <li>操作系统：Centos、Ubuntu</li></ul> <h2 id="二、云端部署"><a href="#二、云端部署" class="header-anchor">#</a> 二、云端部署</h2> <h3 id="_2-1-基础环境初始化"><a href="#_2-1-基础环境初始化" class="header-anchor">#</a> 2.1 基础环境初始化</h3> <p>在命令行执行以下命令：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token builtin class-name">export</span> <span class="token assign-left variable">node</span><span class="token operator">=</span>server <span class="token punctuation">;</span> /bin/bash <span class="token parameter variable">-c</span> <span class="token string">&quot;<span class="token variable"><span class="token variable">$(</span><span class="token function">curl</span> <span class="token parameter variable">-fsSL</span> https://edgex-prod.oss-cn-hangzhou.aliyuncs.com/iBUILDING/installer.sh<span class="token variable">)</span></span>&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>执行效果</strong></p> <p>一键安装KubeEdge运行所需的基础环境，包括：docker、k8s、ipvs等。</p> <p><strong>适用场景</strong></p> <ul><li>一台全新的服务器</li> <li>之前已经安装过docker或k8s相关服务，但因为某些原因无法正常使用，需要进行重置处理。</li></ul> <p><strong>脚本逻辑:</strong></p> <ol><li>运行环境识别：架构类型，操作系统类型</li> <li>资源备份：Docker镜像</li> <li>重置环境：
<ul><li>卸载服务：Docker、K8S、IPVS、KubeEdge。</li> <li>清理目录：docker、k8s、KubeEdge相关目录</li> <li>重置网卡、iptable、ipvs</li></ul></li> <li>安装KubeEdge、IPVS、Docker、K8S</li> <li>Docker配置调优
<ul><li>cgroupdriver设置为<code>systemd</code>。</li> <li>限制单个容器的日志大小，默认：100mb。</li> <li>设置docker镜像代理为：<code>https://dockerproxy.com</code></li> <li>还原Docker镜像</li></ul></li> <li>安装 helm。</li></ol> <h3 id="_2-2-启动kubeedge云端服务"><a href="#_2-2-启动kubeedge云端服务" class="header-anchor">#</a> 2.2 启动KubeEdge云端服务</h3> <p>在命令行执行以下命令：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>/bin/bash <span class="token parameter variable">-c</span> <span class="token string">&quot;<span class="token variable"><span class="token variable">$(</span><span class="token function">curl</span> <span class="token parameter variable">-fsSL</span> https://edgex-prod.oss-cn-hangzhou.aliyuncs.com/iBUILDING/init-kubeedge-cloud.sh<span class="token variable">)</span></span>&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>执行效果</strong></p> <p>一键完成K8S、KubeEdge的初始化。</p> <p><strong>适用场景</strong></p> <ul><li>一台全新的K8S环境</li> <li>此前安装过K8S或者KubeEdge，需要对其重置（<strong>此类情况需慎用，该操作会清除本机上的所有k8s资源</strong>）。</li></ul> <p><strong>脚本逻辑:</strong></p> <ol><li>指定云端公网IP。
执行脚本后控制台会出现如下信息，需要输入当前服务器的<strong>公网IP</strong>。<div class="language-shell line-numbers-mode"><pre class="language-shell"><code>PUBLIC_IP:
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div>输入IP后敲回车键会打印：<code>Prepare to set up a kubeEdge environment for {public_ip}</code></li> <li>重置服务：kubeEdge、K8S、iptables、ipvs</li> <li>初始化k8s</li> <li>安装flannel</li> <li>初始化KubeEdge</li> <li>生成边缘接入配置。</li></ol> <h2 id="三、边端部署"><a href="#三、边端部署" class="header-anchor">#</a> 三、边端部署</h2> <h3 id="_3-1-基础环境初始化"><a href="#_3-1-基础环境初始化" class="header-anchor">#</a> 3.1 基础环境初始化</h3> <p>边缘侧的环境初始化基本同云端一致，差别在于不需要安装helm。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token builtin class-name">export</span> <span class="token assign-left variable">node</span><span class="token operator">=</span>client <span class="token punctuation">;</span> /bin/bash <span class="token parameter variable">-c</span> <span class="token string">&quot;<span class="token variable"><span class="token variable">$(</span><span class="token function">curl</span> <span class="token parameter variable">-fsSL</span> https://edgex-prod.oss-cn-hangzhou.aliyuncs.com/iBUILDING/installer.sh<span class="token variable">)</span></span>&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_3-2-搭建kubeedge环境"><a href="#_3-2-搭建kubeedge环境" class="header-anchor">#</a> 3.2 搭建KubeEdge环境</h3> <p>当云端执行完毕 <a href="#_2-2-%E5%90%AF%E5%8A%A8KubeEdge%E4%BA%91%E7%AB%AF%E6%9C%8D%E5%8A%A1">2.2 启动KubeEdge云端服务</a> ，会在控制台打印客户端的接入指令。</p> <p>当然，你也可以通过以下步骤完成边缘侧节点与云端节点的配网动作。</p> <ol><li>在云端执行如下命令生成Token<div class="language-shell line-numbers-mode"><pre class="language-shell"><code>keadm gettoken
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li> <li>边缘节点执行以下命令加入云节点<div class="language-shell line-numbers-mode"><pre class="language-shell"><code>keadm <span class="token function">join</span> <span class="token punctuation">\</span>
   <span class="token parameter variable">--runtimetype</span><span class="token operator">=</span>docker <span class="token punctuation">\</span>
   <span class="token parameter variable">--cgroupdriver</span><span class="token operator">=</span>systemd <span class="token punctuation">\</span>
   --with-mqtt<span class="token operator">=</span>false <span class="token punctuation">\</span>
   --cloudcore-ipport<span class="token operator">=</span><span class="token operator">&lt;&lt;</span>云端公网IP<span class="token operator">&gt;&gt;</span>:10000 <span class="token punctuation">\</span>
   <span class="token parameter variable">--token</span><span class="token operator">=</span><span class="token operator">&lt;&lt;</span>云端生成的Token<span class="token operator">&gt;&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div></li></ol> <div class="custom-block warning"><p class="custom-block-title">注意</p> <p><strong>重置KubeEdge</strong></p> <p>如若边缘节点因为一些异常情况需要重新安装KubeEdge，可执行以下命令再重新按照 <a href="#_3-2-%E6%90%AD%E5%BB%BAkubeedge%E7%8E%AF%E5%A2%83">搭建KubeEdge环境</a> 步骤部署环境。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>keadm reset <span class="token parameter variable">--force</span>
<span class="token function">rm</span> <span class="token parameter variable">-rf</span> /etc/kubeedge/
<span class="token function">rm</span> <span class="token parameter variable">-rf</span> /etc/cni/net.d
<span class="token function">ifconfig</span> cni0 down
<span class="token function">ip</span> <span class="token function">link</span> delete cni0
iptables <span class="token parameter variable">-F</span> <span class="token operator">&amp;&amp;</span> iptables <span class="token parameter variable">-t</span> nat <span class="token parameter variable">-F</span> <span class="token operator">&amp;&amp;</span> iptables <span class="token parameter variable">-t</span> mangle <span class="token parameter variable">-F</span> <span class="token operator">&amp;&amp;</span> iptables <span class="token parameter variable">-X</span>
ipvsadm <span class="token parameter variable">-C</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div></div> <h2 id="四、效果演示"><a href="#四、效果演示" class="header-anchor">#</a> 四、效果演示</h2> <ol><li>云端执行以下命令部署nginx。</li></ol> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">cat</span> <span class="token operator">&lt;&lt;</span><span class="token string">EOF<span class="token bash punctuation"> <span class="token operator">|</span> kubectl apply <span class="token parameter variable">-f</span> -</span>
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
  nodeSelector:
    &quot;node-role.kubernetes.io/edge&quot;: &quot;&quot;
EOF</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>再执行<code>kubectl get pod -owide</code>确认部署结果。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment"># kubectl get pod -o wide</span>
NAME    READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES
nginx   <span class="token number">1</span>/1     Running   <span class="token number">0</span>          11s   <span class="token number">172.17</span>.0.2   ecs-8f95   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>           <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>当然，也可以登录边缘节点执行<code>docker ps</code>作二次确认。</p> <h2 id="五、开启反向隧道"><a href="#五、开启反向隧道" class="header-anchor">#</a> 五、开启反向隧道</h2> <p>KubeEdge默认没有开启反向隧道，当需要在云端对边缘侧的容器执行<code>kubectl exec</code>或者<code>kubectl logs</code>操作时，需要先开启反向隧道。</p> <h3 id="_5-1-云端"><a href="#_5-1-云端" class="header-anchor">#</a> 5.1 云端</h3> <ol><li>云端执行以下命令，并从中提取<code>ipTunnelPort</code>的IP和端口配置，例如：<code>{&quot;ipTunnelPort&quot;:{&quot;192.168.0.248&quot;:10351},&quot;port&quot;:{&quot;10351&quot;:true}}</code></li></ol> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>kubectl get cm tunnelport <span class="token parameter variable">-nkubeedge</span> <span class="token parameter variable">-oyaml</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ol start="2"><li>设置iptables。</li></ol> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>iptables <span class="token parameter variable">-t</span> nat <span class="token parameter variable">-A</span> OUTPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--dport</span> <span class="token number">10351</span> <span class="token parameter variable">-j</span> DNAT <span class="token parameter variable">--to</span> <span class="token number">192.168</span>.0.248:10003
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="custom-block tip"><p class="custom-block-title">提示</p> <p>如果不确定当前环境的iptables配置是否被污染，可通过以下命令重置：</p> <p><code>iptables -F &amp;&amp; iptables -t nat -F &amp;&amp; iptables -t mangle -F &amp;&amp; iptables -X</code></p></div> <h3 id="_5-2-边缘端"><a href="#_5-2-边缘端" class="header-anchor">#</a> 5.2 边缘端</h3> <ol><li>编辑edgecore.yaml，将<code>enable</code>设置为true，其余不动。<code>vi /etc/kubeedge/config/edgecore.yaml</code></li></ol> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>
  edgeStream:
    enable: <span class="token boolean">true</span>
    handshakeTimeout: <span class="token number">30</span>
    readDeadline: <span class="token number">15</span>
    server: PUBLIC_IP:10004
    tlsTunnelCAFile: /etc/kubeedge/ca/rootCA.crt
    tlsTunnelCertFile: /etc/kubeedge/certs/server.crt
    tlsTunnelPrivateKeyFile: /etc/kubeedge/certs/server.key
    writeDeadline: <span class="token number">15</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><ol start="2"><li>重启服务<code>systemctl restart edgecore.service</code></li></ol> <hr> <p>自此，便完成了云边一体化集群的搭建。下面我们列举了过程中遇到的意外情况及解决办法，后续如有新的问题将会持续更新本文。</p> <h2 id="问题集锦"><a href="#问题集锦" class="header-anchor">#</a> 问题集锦</h2> <ol><li>云端部署应用的时候容器一直无法创建，登录边缘节点观察<code>/var/log/messages</code>日志出现以下内容：</li></ol> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>iptables <span class="token parameter variable">--wait</span> <span class="token parameter variable">-t</span> filter <span class="token parameter variable">-A</span> DOCKER <span class="token operator">!</span> <span class="token parameter variable">-i</span> docker0 <span class="token parameter variable">-o</span> docker0 <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">-d</span> <span class="token number">172.17</span>.0.14 <span class="token parameter variable">--dport</span> <span class="token number">59740</span> <span class="token parameter variable">-j</span> ACCEPT
iptables: No chain/target/match by that name.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><div class="custom-block tip"><p class="custom-block-title">解决方案</p> <p>边缘侧执行：<code>iptables --wait -t filter -N DOCKER</code></p></div></div></div>  <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/06/30, 10:28:27</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/416f35/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">基于HTTP插件的模拟设备数据上报</div></a> <!----></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/416f35/" class="prev">基于HTTP插件的模拟设备数据上报</a></span> <!----></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"><a href="https://gitee.com/iBUILDING-X" title="Gitee" target="_blank" class="iconfont icon-gitee"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2023
    <span>iBUILDING</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.ffe9b366.js" defer></script><script src="/assets/js/2.9760a328.js" defer></script><script src="/assets/js/13.3fd35f26.js" defer></script>
  </body>
</html>
